package com.jinyi.wwdeng.ui

import android.view.View
import com.jinyi.base.base.BaseActivity
import com.jinyi.base.utils.BarUtils
import com.jinyi.base.utils.thread.TimingThread
import com.jinyi.wwdeng.R
import com.jinyi.wwdeng.databinding.ActWelcomeBinding
import com.jinyi.wwdeng.ui.permission.PermissionAct

/**
 * JinYiTest
 * @Author wwdeng
 * @CreateTime: 2024/4/16 13:33
 * @Annotation：欢迎页面
 */
class WelcomeAct: BaseActivity(),TimingThread.ITimingThreadListener {

    private lateinit var binding: ActWelcomeBinding
    //倒计时
    private var mCountDown = 3
    private var timeThread: TimingThread? = null

    override fun getRootView(): View {
        binding = ActWelcomeBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun initView() {
        setTitleBarVisibility(View.GONE)
        BarUtils.setStatusBarLightMode(this, true)

        binding.tvWelcome.text = String.format(getString(R.string.welcome_to_app),getString(R.string.app_name))
    }

    override fun initListener() {

    }

    override fun initData() {
        startTimeThread()
    }

    /* 启动倒计时 */
    private fun startTimeThread(){
        mCountDown = 3
        if (timeThread == null){
            timeThread = TimingThread()
            timeThread!!.setThreadDelayMillis(1000)
            timeThread!!.setLoadListener(this)
        }
        timeThread!!.startThread()
    }

    override fun onLoading() {
        if (mCountDown <= 1){
            timeThread!!.stopThread()
            onIntent(PermissionAct::class.java)
            finish()
            return
        }
        mCountDown--
    }

    override fun onDestroy() {
        super.onDestroy()
        if (timeThread != null){
            timeThread!!.stopThread()
            timeThread = null
        }
    }
}